package com.ostrich.module_main.ui

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import com.ostrich.module_main.R
import com.tencent.mmkv.MMKV


class SplashActivity : AppCompatActivity() {
    private val handler:Handler by lazy { Handler() }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main_activity_splash)

        handler.postDelayed({
            //读取数据
            if(!MMKV.defaultMMKV().decodeBool("gone")){
                runOnUiThread {
                    startActivity(Intent(this,GuideActivity::class.java))
                }

            }else{
                runOnUiThread {
                    startActivity(Intent(this,MainActivity::class.java))
                }


            }
        },3000)
    }

    override fun onStop() {
        super.onStop()
        finish()
    }

    override fun onDestroy() {
        super.onDestroy()
        //activity销毁时移除所有消息,防止内存泄漏 重要点XXXXXX
        handler.removeCallbacksAndMessages(null)
    }
}